#include <iostream>

#include <cstdlib>

#include <unistd.h>
#include <pthread.h>


void* threadRun(void* args)
{
    const char* str = (const char*)args;
    for (int i = 0; i < 5; ++i)
    {
        std::cout << "new thread: " << getpid() << ' ' << str << std::endl;
        sleep(1);
    }
    return (void*)1;
}

int main()
{
    pthread_t tid;
    pthread_create(&tid, nullptr, threadRun, (void*)"Thread 1");

    sleep(2);
    pthread_cancel(tid);

    void* retval;
    pthread_join(tid, &retval);
    std::cout << "main thread quit ..., ret: " << (long long int)retval << std::endl;

    return 0;
}